package org.hcyspartnoc.luoxin.controller.searchtopic;


import org.hcyspartnoc.luoxin.common.core.AjaxResult;
import org.hcyspartnoc.luoxin.common.core.annotation.Log;
import org.hcyspartnoc.luoxin.common.core.annotation.PreAuthorize;
import org.hcyspartnoc.luoxin.common.core.enums.BusinessType;
import org.hcyspartnoc.luoxin.common.exception.searchtopic.QuestionBankException;
import org.hcyspartnoc.luoxin.pojo.dto.searchtopic.QuestionBankDto;
import org.hcyspartnoc.luoxin.pojo.vo.searchtopic.QuestionBankVO;
import org.hcyspartnoc.luoxin.service.searchtopic.QuestionBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question/bank")
public class QuestionBankController {
    @Autowired
    private QuestionBankService questionBankMapper;
    @Log(title = "题库·添加·单个", businessType = BusinessType.INSERT)
    @PreAuthorize(auth = "question:bank:insert", descr = "添加题库")
    @PostMapping("/insert")
    public AjaxResult insertQuestionBank(@RequestBody QuestionBankDto questionBankDto) throws QuestionBankException {
        questionBankMapper.createQuestionBank(questionBankDto);
        return AjaxResult.success();
    }
    @Log(title = "题库·修改·单个", businessType = BusinessType.UPDATE)
    @PreAuthorize(auth = "question:bank:update", descr = "修改题库")
    @PutMapping("/update")
    public AjaxResult updateQuestionBank(@RequestBody QuestionBankDto questionBankDto) throws QuestionBankException {
        questionBankMapper.updateQuestionBank(questionBankDto);
        return AjaxResult.success();
    }
    @Log(title = "题库·查询·全部", businessType = BusinessType.OTHER)
    @PreAuthorize(auth = "question:bank:select", descr = "查询题库")
    @GetMapping("/select")
    public AjaxResult getQuestionBank() throws QuestionBankException {
        List<QuestionBankVO> questionBankVO= questionBankMapper.getQuestionBank();
        return AjaxResult.success(questionBankVO);
    }
    @Log(title = "题库·删除·单个", businessType = BusinessType.DELETE)
    @PreAuthorize(auth = "question:bank:delete", descr = "删除题库")
    @DeleteMapping("/delete")
    public AjaxResult deleteQuestionBank(@RequestParam Long id) throws QuestionBankException {
        questionBankMapper.deleteQuestionBank(id);
        return AjaxResult.success();
    }
    @Log(title = "题库·删除·批量", businessType = BusinessType.DELETE)
    @PreAuthorize(auth = "question:banks:delete", descr = "批量删除题库")
    @DeleteMapping("/deletes")
    public AjaxResult deleteQuestionBanks(@RequestParam List<Integer> ids) throws QuestionBankException {
        questionBankMapper.deleteQuestionBanks(ids);
        return AjaxResult.success();
    }
}
